package com.example.message;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

@Component
public class MessageSourceService {

    @Autowired
    private MessageSource messageSource;

    public MessageSourceService() {
    }

    public String getMessage(String messageKey) {
        return this.messageSource.getMessage(messageKey, (Object[])null, LocaleContextHolder.getLocale());
    }

    //此方法是用来传入占位符时候用的
    public String getMessage(String messageKey, Object... args) {
        return this.messageSource.getMessage(messageKey, args, LocaleContextHolder.getLocale());
    }
}
